<%-- 
    Document   : MarksForStudentList
    Created on : 01.03.2012, 14:38:53
    Author     : Alexey Akimov <frinatella@gmail.com>
--%>

<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="student_report.DbConnection"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Marks For Students List</title>
    </head>
    <body>
        <h1>Marks For Students List</h1>
        <%
            String studentId = request.getParameter("studentId"), surname = request.getParameter("surname"), name = request.getParameter("name"), groupNumber = request.getParameter("groupNumber");
            if (null != studentId && null != surname && null != name && null != groupNumber) {
                out.print("<h2>For student " + surname + " " + name + " from group " + groupNumber + "</h2>");
            }
        %>
        <table border="1"><tr><td>Mark Id</td><td>Subject Name</td><td>Mark Value</td></tr>
        <%
        
         try {
                Connection connection = DbConnection.getConnection();
                ResultSet resultSet = connection.createStatement().executeQuery(
                        "select MARK_ID, SUBJECT_NAME, MARK_VALUE from MARKS M, SUBJECTS S where M.SUBJECT_ID = S.SUBJECT_ID and STUDENT_ID = " + studentId);
                while (resultSet.next()) {
                    out.println("<tr><td>" + resultSet.getString("MARK_ID") + "</td>"
                            + "<td>" + resultSet.getString("SUBJECT_NAME") + "</td>"
                            + "<td>" + resultSet.getString("MARK_VALUE") + "</td></tr>");
                }
                } catch (SQLException ex) {
                    out.print("<h3>Marks for students list loading failed.</h3>");
                }
        %>
        </table>
    </body>
</html>
